package Shopfashion;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Update
 */
@WebServlet("/Update")
public class Update extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Update() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");

        String model = request.getParameter("model");
        String mausac =request.getParameter("mausac");
        String size = request.getParameter("size");
        String chatlieu =request.getParameter("chatlieu");
        Double dongia = Double.parseDouble(request.getParameter("dongia"));
        Double vongnguc = Double.parseDouble(request.getParameter("vongnguc"));
        Double vongeo =Double.parseDouble(request.getParameter("vongeo"));
        Double vongmong =Double.parseDouble(request.getParameter("vongmong"));
        String hinhanh =request.getParameter("hinhsp");
        String ngaynhap =request.getParameter("ngaynhap");
        String mota =request.getParameter("mota");

        SanPham sp = new SanPham(model, mausac, size, chatlieu, dongia, vongnguc, vongeo, vongmong, hinhanh, ngaynhap, mota);

		ConnectDB db = new ConnectDB();
		try {
			if (db.UpdateProduct(model, sp))
				response.sendRedirect("San_Pham.jsp");
			else
				response.sendRedirect("error.jsp");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
